//
//  RNOLTabBarController.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/2.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLTabBarController.h"
#import "RNOLNavigationController.h"
#import "RNOLHomePageViewController.h"
#import "RNOLMoneyManagerViewController.h"
#import "RNOLDiscovererViewController.h"
#import "RNOLMeViewController.h"

@interface RNOLTabBarController ()<UITabBarControllerDelegate>

@end

@implementation RNOLTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self createTabSubViewControllers];
    self.tabBar.tintColor = kAppMainColor;
    [self.tabBar setBackgroundImage: [UIImage imageNamed:@"tabbar_bg"]];
    //去掉tabBar顶部线条
    [UITabBar appearance].clipsToBounds = YES;
    self.delegate = self;
}

#pragma mark- <UITabBarControllerDelegate>
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {

    return YES;
}


- (void)createTabSubViewControllers{
    RNOLHomePageViewController *homeVC = [[RNOLHomePageViewController alloc] init];
    [self createNavgationViewControllerWithSubViewController: homeVC title: @"首页" image:@"rnol_home_normal" selectedImage:@"rnol_home_selected"];
    
    RNOLMoneyManagerViewController *moneyManagerVC = [[RNOLMoneyManagerViewController alloc] init];
    [self createNavgationViewControllerWithSubViewController: moneyManagerVC title: @"理财" image:@"rnol_licai_normal" selectedImage:@"rnol_licai_selected"];
    
    RNOLDiscovererViewController *discovererVC = [[RNOLDiscovererViewController alloc] init];
    [self createNavgationViewControllerWithSubViewController: discovererVC title: @"发现" image:@"rnol_discover_normal" selectedImage:@"rnol_discover_selected"];
    
    RNOLMeViewController *meVC = [[RNOLMeViewController alloc] init];
    [self createNavgationViewControllerWithSubViewController: meVC title: @"我的" image:@"rnol_me_normal" selectedImage:@"rnol_me_selected"];

}

- (void )createNavgationViewControllerWithSubViewController:(UIViewController *)subVC
                                                      title:(NSString *)title
                                                      image:(NSString *)image
                                              selectedImage:(NSString *)selectedImage{
    RNOLNavigationController *wgbNavVC = [[RNOLNavigationController alloc] initWithRootViewController: subVC];
    subVC.navigationItem.title = title;
    subVC.tabBarItem.title = title;
    subVC.tabBarItem.image = [UIImage imageNamed: image];
    subVC.tabBarItem.selectedImage = [UIImage imageNamed: selectedImage];
    [self addChildViewController: wgbNavVC];
}

@end
